package com.teziyou.commodity.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.thrift.TException;
import org.springframework.stereotype.Service;

import com.mytravel.platform.bean.DictionaryBean;
import com.mytravel.platform.bean.Page;
import com.mytravel.platform.service.DictionaryService;
import com.teziyou.commodity.core.thrift.ConnectionManager;

@Service
public class DictService {
	
	@Resource(name="dictConnectionManager")
	private ConnectionManager connectionManager;
	
	private DictionaryService.Client client;
	
	public int deleteDictionaryTrift(int id) {
		try {
			return client.deleteDictionaryTrift(id);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public DictionaryBean getDictionaryById(int dictionaryId) {
		try {
			return client.getDictionaryById(dictionaryId);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public DictionaryBean getDictionaryByType(String type, int value) {
		try {
			return client.getDictionaryByType(type, value);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}

	public List<DictionaryBean> getDictionaryList(String type) {
		try {
			return client.getDictionaryList(type);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}

	public List<DictionaryBean> getDictionarysList(int dictionaryId, Page page) {
		try {
			return client.getDictionarysList(dictionaryId, page);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public void insertDictionaryTrift(DictionaryBean dictionary) {
		try {
			client.insertDictionaryTrift(dictionary);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public String queryAll(String type) {
		try {
			return client.queryAll(type);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}

	public String queryOneForId(int dictionaryId) {
		try {
			return client.queryOneForId(dictionaryId);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		
	}

	public String queryOneForType(String type, int value) {
		try {
			return client.queryOneForType(type, value);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}
	
	public Map<Integer, DictionaryBean> getDictMapByType(String type) {
		try {
			return client.getDictMapByType(type);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

	public int updateDictionaryTrift(DictionaryBean dictionary) {
		try {
			return client.updateDictionaryTrift(dictionary);
		} catch (TException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}
	}

}
